<?php
class SMCore_Admin_Controller_Action_Helper_Utilities extends Zend_Controller_Action_Helper_Abstract
{
    public function alias($text)
    {
        $marTViet   =   array(
            '\\','/','.',' ',"à","á","ạ","ả","ã","â","ầ","ấ","ậ","ẩ","ẫ","ă",
    		"ằ","ắ","ặ","ẳ","ẵ","è","é","ẹ","ẻ","ẽ","ê","ề"
    		,"ế","ệ","ể","ễ",
    		"ì","í","ị","ỉ","ĩ",
    		"ò","ó","ọ","ỏ","õ","ô","ồ","ố","ộ","ổ","ỗ","ơ"
    		,"ờ","ớ","ợ","ở","ỡ",
    		"ù","ú","ụ","ủ","ũ","ư","ừ","ứ","ự","ử","ữ",
    		"ỳ","ý","ỵ","ỷ","ỹ",
    		"đ",
    		"À","Á","Ạ","Ả","Ã","Â","Ầ","Ấ","Ậ","Ẩ","Ẫ","Ă"
    		,"Ằ","Ắ","Ặ","Ẳ","Ẵ",
    		"È","É","Ẹ","Ẻ","Ẽ","Ê","Ề","Ế","Ệ","Ể","Ễ",
    		"Ì","Í","Ị","Ỉ","Ĩ",
    		"Ò","Ó","Ọ","Ỏ","Õ","Ô","Ồ","Ố","Ộ","Ổ","Ỗ","Ơ"
    		,"Ờ","Ớ","Ợ","Ở","Ỡ",
    		"Ù","Ú","Ụ","Ủ","Ũ","Ư","Ừ","Ứ","Ự","Ử","Ữ",
    		"Ỳ","Ý","Ỵ","Ỷ","Ỹ",
    		"Đ"
		);
		
		$marKoDau =   array(
    		'-','-','','-',"a","a","a","a","a","a","a","a","a","a","a"
    		,"a","a","a","a","a","a",
    		"e","e","e","e","e","e","e","e","e","e","e",
    		"i","i","i","i","i",
    		"o","o","o","o","o","o","o","o","o","o","o","o"
    		,"o","o","o","o","o",
    		"u","u","u","u","u","u","u","u","u","u","u",
    		"y","y","y","y","y",
    		"d",
    		"A","A","A","A","A","A","A","A","A","A","A","A"
    		,"A","A","A","A","A",
    		"E","E","E","E","E","E","E","E","E","E","E",
    		"I","I","I","I","I",
    		"O","O","O","O","O","O","O","O","O","O","O","O"
    		,"O","O","O","O","O",
    		"U","U","U","U","U","U","U","U","U","U","U",
    		"Y","Y","Y","Y","Y",
    		"D"
		);
		$alias	=	str_replace($marTViet, $marKoDau, trim($text));
		return $alias;
    }
	/**
	 * Utility function to sort an array of objects on a given field
	 *
	 * @static
	 * @param	array	$arr		An array of objects
	 * @param	string	$k			The key to sort on
	 * @param	int		$direction	Direction to sort in [1 = Ascending] [-1 = Descending]
	 * @return	array	The sorted array of objects
	 * @since	1.5
	 */
	public function sortObjects( &$a, $k, $direction=1 )
	{
		$GLOBALS['JAH_so'] = array(
			'key'		=> $k,
			'direction'	=> $direction
		);
		usort( $a, array('JArrayHelper', '_sortObjects') );
		unset( $GLOBALS['JAH_so'] );

		return $a;
	}
	/**
	 * Private callback function for sorting an array of objects on a key
	 *
	 * @static
	 * @param	array	$a	An array of objects
	 * @param	array	$b	An array of objects
	 * @return	int		Comparison status
	 * @since	1.5
	 * @see		JArrayHelper::sortObjects()
	 */
	private function _sortObjects( &$a, &$b )
	{
		$params = $GLOBALS['JAH_so'];
		if ( $a->$params['key'] > $b->$params['key'] ) {
			return $params['direction'];
		}
		if ( $a->$params['key'] < $b->$params['key'] ) {
			return -1 * $params['direction'];
		}
		return 0;
	}
	/**
	 * Gets the extension of a file name
	 *
	 * @param string $file The file name
	 * @return string The file extension
	 */
	public function getext($file) {
		$dot = strrpos($file, '.') + 1;
		return substr($file, $dot);
	}
}

?>